/* $Id: UserReqFacadeImpl.java 
 * Copyright (C) 2011, TRAKHEES
 *  
 * Revision History
 *
 * Date  			Author 		    	Remarks
 * ---------------------------------------------------------------------------------
 *
 */
package ae.pcfc.etks.online.common.facade.provider;

import org.springframework.transaction.annotation.Transactional;

import ae.pcfc.etks.online.common.domain.UserReq;
import ae.pcfc.etks.online.common.domain.manager.UserReqDomainObjectManager;
import ae.pcfc.etks.online.common.exception.BadApplicationRequestException;
import ae.pcfc.etks.online.common.facade.UserReqFacade;
import ae.pcfc.etks.online.common.vo.ClientCompanyReqVO;
import ae.pcfc.etks.online.common.vo.ClientPersonReqVO;

public class UserReqFacadeImpl extends BaseFacade implements UserReqFacade {
    	/*
	 * Here we coordinate between the all interacting business domain objects
	 * (BO), transactions are maintained here. use case business validation are
	 * maintained here (that requires DB checks or retrieving data from DB)
	 */
	private UserReqDomainObjectManager userReqDomainObjectManager;

	/**
	 * setUserReqDomainObjectManager
	 * 
	 * @param userReqDomainObjectManager
	 * void
	 */
	public void setUserReqDomainObjectManager(
			UserReqDomainObjectManager userReqDomainObjectManager) {
		this.userReqDomainObjectManager = userReqDomainObjectManager;
	}
	
	/**
	 * findClientPersonReqByApplicationId
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UserReqFacade#findClientPersonReqByApplicationId(java.lang.String)
	 * 
	 */
	@Transactional ( readOnly = true )
	public ClientPersonReqVO findClientPersonReqByApplicationId(String applicationId){
		
		ClientPersonReqVO clientPersonReqVO = new ClientPersonReqVO();
		UserReq userReq = userReqDomainObjectManager.findByApplicationId(applicationId);
		
		if(userReq != null)
		{
			getMapper().map(userReq, clientPersonReqVO);
			return clientPersonReqVO;
		}
		throw new BadApplicationRequestException(applicationId);
	}
	
	/**
	 * findClientCompanyReqByApplicationId
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UserReqFacade#findClientCompanyReqByApplicationId(java.lang.String)
	 * 
	 */
	@Transactional ( readOnly = true )
	public ClientCompanyReqVO findClientCompanyReqByApplicationId(String applicationId){
		ClientCompanyReqVO clientCompanyReqVO = new ClientCompanyReqVO();
		UserReq userReq = userReqDomainObjectManager.findByApplicationId(applicationId);
		if(userReq != null){
			getMapper().map(userReq, clientCompanyReqVO);
			return clientCompanyReqVO;
		}
		throw new BadApplicationRequestException(applicationId);
	}
}
